<template>
  <div>
    <el-skeleton style="height: 50vh" :rows="4" :loading="loading" animated>
      <el-table
        :height="400"
        :data="tableData"
        style="width: 100%"
        v-loading="loading"
        :header-cell-style="{
          background: '#F7F9FD',
          color: '#000',
          height: '48px',
          borderTop: '1px soild #E4E8F2'
        }"
      >
        <template #empty>
          <el-empty :image-size="150" description="暂无数据"></el-empty>
        </template>

        <el-table-column type="index" label="序号" width="80">
          <template v-slot="scope">
            <span>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="witnessName" label="验收记录"> </el-table-column>
        <el-table-column fixed="right" label="操作" width="80">
          <template #default="{ row }">
            <el-button
              type="text"
              size="small"
              @click="handleAdd(row)"
              v-if="Number(row.isShow) !== 1"
              >添加</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- <re-pagination
        v-if="total > 0"
        :total="total"
        v-model:page="pageState.pageNum"
        v-model:limit="pageState.pageSize"
        @pagination="handleChangePage"
      /> -->
    </el-skeleton>
  </div>
</template>
<script lang="ts">
import { useRoute } from "vue-router";
import { defineComponent, ref } from "vue";
import {
  witnessCheckItemList,
  witnessCheckItemListAdd
} from "/@/api/construction";
// import RePagination from "/@/components/RePagination/index.vue";
export default defineComponent({
  name: "checkList",
  props: {
    checkItem: {
      type: Object,
      default: () => {}
    }
  },
  // components: { RePagination },
  emits: ["closeList"],
  setup() {
    const total = ref<number>(0);
    const tableData = ref([]);
    const loading = ref<boolean>(false);
    const route = useRoute();
    const pageState = {
      pageNum: 1,
      pageSize: 10000,
      witnessId: route.query.id
    };
    //获取检查列表
    const getCheckRecordList = async () => {
      try {
        loading.value = true;
        const { code, data } = await witnessCheckItemList(pageState);
        if (code === 200) {
          tableData.value = data.list;
          total.value = data.rows;
        }
      } catch (err) {
        console.log(err);
      } finally {
        loading.value = false;
      }
    };
    const handleAdd = async data => {
      try {
        loading.value = true;
        const { code } = await witnessCheckItemListAdd({ id: data.id });
        if (code === 200) {
          getCheckRecordList();
        }
      } catch (error) {
        loading.value = false;
      }
    };
    const handleChangePage = () => {
      getCheckRecordList();
    };

    getCheckRecordList();
    return {
      tableData,
      loading,
      pageState,
      getCheckRecordList,
      handleChangePage,
      total,
      handleAdd
    };
  }
});
</script>
<style lang="scss" scoped>
:deep .el-dialog__body {
  padding: 16px;
}

:deep .el-table {
  border: none;
}

:deep .el-table__fixed-right::before {
  display: none;
}
</style>
